package com.ruoyi.common.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JSONUtils {
	private final static ObjectMapper MAPPER = new ObjectMapper();

    /**
     * 将对象序列化为json字符串。
     */
    public static <T> String serialize(T object) {
        String json = null;
        try {
            json = MAPPER.writeValueAsString(object);
        } catch (JsonProcessingException e) {
            
        }
        return json;
    }

    /**
     * 将json字符串反序列化为对象
     */
    public static <T> T deserialize(String jsonData, Class<T> beanType) {
        T object = null;
        try {
            object = MAPPER.readValue(jsonData, beanType);
        } catch (JsonProcessingException e) {
           
        }
        return object;
    }
}
